package org.rency.common.messager.beans;

import java.io.Serializable;
import java.util.List;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.rency.common.messager.exception.MessageException;
import org.springframework.util.Assert;

/**
 * 发送短信实体类
 * @author: user_rcy@163.com
 * </br>Created on
 * @version: V1.0.0
 * @since JDK 1.8
 */
public class SMSWebChineseEntity implements Serializable {

    /**
	 * 
	 */
	private static final long serialVersionUID = -3801210922433600812L;

	private SMSPlateform smsPlateform = SMSPlateform.WEBCHINESE;

    /**
     * 接入短信平台用户名
     */
    private String uid;

    /**
     * 接入短信平台安全密钥
     */
    private String key;

    /**
     * 接收人手机号
     */
    private String receiveMobile;

    /**
     * 短信内容
     */
    private String content;
    
    private String url;
    
    public void validate(){
    	try{
    		Assert.hasLength(uid);
    		Assert.hasLength(key);
    		Assert.hasLength(receiveMobile);
    		Assert.hasLength(content);
    		Assert.hasLength(url);
    	}catch(Exception e){
    		throw new MessageException("参数校验异常.",e);
    	}
    }

    public SMSPlateform getSmsPlateform() {
        return smsPlateform;
    }

    public void setSmsPlateform(SMSPlateform smsPlateform) {
        this.smsPlateform = smsPlateform;
    }

    public String getUid() {
        return uid;
    }

    public void setUid(String uid) {
        this.uid = uid;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getReceiveMobile() {
        return receiveMobile;
    }

    public void setReceiveMobile(String receiveMobile) {
        this.receiveMobile = receiveMobile;
    }

    public void setReceiveMobile(List<String> receiveMobiles) {
        if(receiveMobiles.size() > 100){
            throw new IllegalArgumentException("一次最多发送100个");
        }
        StringBuilder builder = new StringBuilder();
        for(String mobile : receiveMobiles){
            builder.append(mobile);
            builder.append(",");
        }
        String mobileString = builder.toString().substring(0,builder.length()-1);
        this.receiveMobile = mobileString;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String toString(){
        return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
    }
}
